﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace space_scavenger
{
    class Player : Entity
    {
        private int movementSpeed;
        private int health;
        private int armor;
        private int attackPower;
        private int weaponSpeed;

        //private ProjectileFactory projectileFactory;

        public int MovementSpeed
        {
            get 
            {
                return movementSpeed;
            }
            set 
            {
                movementSpeed = value;
            }
        }

        public int Health
        {
            get
            {
                return health;
            }
            set
            {
                health = value;
            }
        }

        public int Armor
        {
            get
            {
                return armor;
            }
            set
            {
                armor = value;
            }
        }

        public int AttackPower
        {
            get
            {
                return attackPower;
            }
            set
            {
                attackPower = value;
            }
        }

        public int WeaponSpeed
        {
            get
            {
                return weaponSpeed;
            }
            set
            {
                weaponSpeed = value;
            }
        }

        /*public ProjectileFactory Gun
        {
            get
            {
                return projectileFactory;
            }
            set
            {
                projectileFactory = value;
            }
        }*/

        public Player(Vector2 position, Vector2 startingVelocity, Rectangle hitbox,
            Texture2D image, int speed, int health, int armor, int attack) 
            : base(position, startingVelocity, hitbox, image)
        {
            MovementSpeed = speed;
            Health = health;
            Armor = armor;
            AttackPower = attack;
        }

        public void UpdateEquipment()
        {
            /* iArmor = Inventory.getArmor();
             * iAttackPower = Inventory.getWeapon();
             * iMovementSpeed = Inventory.getEngine();
             */
        }

        public void FireWeapon()
        {
            //Bullet.Generate(base.PositionX,base.PositionY,iAttackPower,iWeaponSpeed);
        }

        public void TakeDamage(int damage)
        {
            health -= damage * (1/armor);
        }

        public Boolean IsDead()
        {
            if (health <= 0)
                return true;
            return false;
        }

        public void MoveUp()
        {
            //base.PositionY -= movementSpeed;
            Vector2 newVelocity = Velocity;
            newVelocity.Y = -movementSpeed;
            newVelocity.Normalize();
            newVelocity.X *= movementSpeed;
            newVelocity.Y *= movementSpeed;
            Velocity = newVelocity;
        }

        public void MoveDown()
        {
            //base.PositionY += movementSpeed;
            Vector2 newVelocity = Velocity;
            newVelocity.Y = movementSpeed;
            newVelocity.Normalize();
            newVelocity.X *= movementSpeed;
            newVelocity.Y *= movementSpeed;
            Velocity = newVelocity;
        }

        public void MoveLeft()
        {
            //base.PositionX -= movementSpeed;
            Vector2 newVelocity = Velocity;
            newVelocity.X = -movementSpeed;
            newVelocity.Normalize();
            newVelocity.X *= movementSpeed;
            newVelocity.Y *= movementSpeed;
            Velocity = newVelocity;
        }

        public void MoveRight()
        {
            //base.PositionX += movementSpeed;
            Vector2 newVelocity = Velocity;
            newVelocity.X = movementSpeed;
            newVelocity.Normalize();
            newVelocity.X *= movementSpeed;
            newVelocity.Y *= movementSpeed;
            Velocity = newVelocity;
        }

        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            base.Draw(spriteBatch, gameTime);
        }

        public override void Update(InputState state, GameTime gameTime)
        {
            if (state.checkCommand(InputState.Commands.MOVE_UP_COMMAND))
            {
                MoveUp();
            }
            else if (state.checkCommand(InputState.Commands.MOVE_DOWN_COMMAND))
            {
                MoveDown();
            }

            if (state.checkCommand(InputState.Commands.MOVE_LEFT_COMMAND))
            {
                MoveLeft();
            }
            else if (state.checkCommand(InputState.Commands.MOVE_RIGHT_COMMAND))
            {
                MoveRight();
            }

            base.Update(state, gameTime);

        }
    }
}